package com.alibaba.citrus.ots.platform.enhance.functions.diff.activity.dataParser;

import com.alibaba.citrus.ots.platform.enhance.functions.diff.activity.constant.ActivityDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.constant.SalesOrderLineDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.dataParser.DataParser;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.common.FieldLineDTO;
import com.alibaba.cz.base.tool.log.Log;
import com.epoch.app.otspricecenter.sdo.ActivityUseRecordRelationSDO;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: qiaojiange
 * @create: 2022/01/18
 * @Description 活动使用记录数据解析器
 */
@Component
public class ActivityUseRecordRelationDataParse extends DataParser {
    /**
     * 日志
     */
    private static Log log = Log.getLogger(ActivityUseRecordRelationDataParse.class);
    /**
     * 数据库字段，映射成对账处理的业务字段(标准字段)
     * key：数据库中的字段，value：转换后的字段,这里的 value 字段也不要重复
     */
    private static Map<String, String> dataBaseFiledMapping = new HashedMap();

    static {
        dataBaseFiledMapping.put("activityId", ActivityDiffStandardFieldDict.ACTIVITY_ID.getFieldCode());
        dataBaseFiledMapping.put("activityTermId", ActivityDiffStandardFieldDict.ACTIVITY_TERM_ID.getFieldCode());
        dataBaseFiledMapping.put("sequenceNo", ActivityDiffStandardFieldDict.SEQUENCE_NO.getFieldCode());
        dataBaseFiledMapping.put("subOrderId", ActivityDiffStandardFieldDict.SUB_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("itemId", ActivityDiffStandardFieldDict.ITEM_ID.getFieldCode());
        dataBaseFiledMapping.put("itemQuantity", ActivityDiffStandardFieldDict.ITEM_QUANTITY.getFieldCode());
        //dataBaseFiledMapping.put("version", ActivityDiffStandardFieldDict.ACTIVITY_USE_RECORD_FEATURES.getFieldCode());
        dataBaseFiledMapping.put("status",ActivityDiffStandardFieldDict.ACTIVITY_USE_RECORD_STATUS.getFieldCode());
        dataBaseFiledMapping.put("activityOccupyFee",ActivityDiffStandardFieldDict.ACTIVITY_OCCUPY_FEE.getFieldCode());

        dataBaseFiledMapping.put("features.serialNumber", SalesOrderLineDiffStandardFieldDict.SERIAL_NUMBER.getFieldCode());
    }

    /**
     * 数据转换
     *
     * @param obj 入参
     * @return
     */
    @Override
    public Map<String, FieldLineDTO> parse(Object obj) {
        Map<String, FieldLineDTO> map = new HashMap<>();
        if (obj instanceof ActivityUseRecordRelationSDO) {
            ActivityUseRecordRelationSDO recordRelationSDO = (ActivityUseRecordRelationSDO) obj;
            return obtainFieldLineMap(dataBaseFiledMapping, recordRelationSDO, recordRelationSDO.getClass());
        }
        return map;
    }

    @Override
    public String obtainProcessType() {
        return "ActivityUseRecordRelationSDO";
    }
}
